package com.xdhl.fu.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xdhl.fu.common.core.utils.JwtUtils;
import com.xdhl.fu.common.security.utils.SecurityUtils;
import com.xdhl.fu.member.domain.MemberBasic;
import com.xdhl.fu.member.domain.MemberPassenger;
import com.xdhl.fu.member.mapper.MemberPassengerMapper;
import com.xdhl.fu.member.service.IMemberBasicService;
import com.xdhl.fu.member.service.IMemberPassengerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 会员乘客信息业务实现
 *
 * @author 朱力维
 * @time 2022/5/27 16:44
 */
@Service
public class MemberPassengerServiceImpl extends ServiceImpl<MemberPassengerMapper, MemberPassenger> implements IMemberPassengerService {
    @Resource
    private IMemberBasicService memberBasicService;

    @Override
    public List<MemberPassenger> getPassengerList() {
        String username = JwtUtils.getUserName(SecurityUtils.getToken());
        LambdaQueryWrapper<MemberBasic> condition = new LambdaQueryWrapper<>();
        condition.eq(MemberBasic::getIdCardNumber, username)
                .or().eq(MemberBasic::getEmail, username)
                .or().eq(MemberBasic::getTelephoneNumber, username);
        condition.select(MemberBasic::getDataId);
        String dataId = memberBasicService.getOne(condition).getDataId();
        LambdaQueryWrapper<MemberPassenger> lqw = new LambdaQueryWrapper<>();
        lqw.eq(MemberPassenger::getMemberDataId, dataId);
        return list(lqw);
    }
}
